clear all
cd "________________"

log using "Table1_Table4.log", replace
*data_long_clean.dta is the long version of the clean dataset
use  "dataset_long_clean.dta", clear

*Table 1
eststo: reghdfe kwh_ temp_, absorb(premise_id#i.hour i.year#i.month#i.hour) cluster(yearwk)
preserve
collapse (mean) kwh_ temp_, by(premise_id year month yearmo sasdate)
eststo: reghdfe kwh_ temp_, absorb(premise_id) cluster(yearmo)
eststo: reghdfe kwh_ temp_, absorb(premise_id year) cluster(yearmo)
eststo: reghdfe kwh_ temp_, absorb(premise_id yearmo) cluster(yearmo)

collapse (mean) kwh_ temp_, by(premise_id year month yearmo)
eststo: reghdfe kwh_ temp_, absorb(premise_id) cluster(yearmo)
eststo: reghdfe kwh_ temp_, absorb(premise_id year) cluster(yearmo)
eststo: reghdfe kwh_ temp_, absorb(premise_id month) cluster(yearmo)

collapse (mean) kwh_ temp_, by(premise_id year)
eststo: reghdfe kwh_ temp_, absorb(premise_id) 

esttab using Table1.tex, replace b(4)
restore


*Table 4
by premise_id sasdate: egen temp_md=mean(temp_)
gen temp_demean=temp_-temp_md
eststo clear

eststo: reghdfe kwh_ temp_md temp_demean, absorb(premise_id#i.hour i.year#i.month#i.hour) cluster(yearwk)
eststo: reghdfe kwh_ temp_, absorb(premise_id#i.hour i.year#i.month#i.hour) cluster(yearwk)

preserve
collapse (mean) kwh_ temp_, by(premise_id year month yearmo sasdate)
eststo: reghdfe kwh_ temp_, absorb(premise_id yearmo) cluster(yearmo)
restore

esttab using Table4.tex, replace b(4)

log close
